<?php
/**
 * 关于发修
 * Author: eecjimmy
 * Date: 2015/6/22
 * Time: 16:02
 */

namespace Wap\Controller;

/**
 * Class AboutController
 * @package Wap\Controller
 */
class ShopController extends WapController
{

	public function index()
	{
		$product = M('product');
		$recommend = $product->field('id,tid,sid,pname,pic')->where(array('is_recommend'=>array('eq',1)))->select();
		
		$this->assign('recommend',$recommend);
		$this->assign('nav',$this->getNav());
		$this->display();
	}

	public function getNav()
	{
		return M()->query('select id,`name`,sort from faxiu_product_type order by sort asc');
	}

	public function index_ajax()
	{
		$product = M('product');
		$p = I('p',1,'intval') < 1 ? 1 : I('p',1,'intval');
		$cateId = I('cateId',1,'intval') < 1 ? 1 : I('cateId',1,'intval');

		$pList = $product->field(true)->where(array('tid'=>$cateId))->limit(3)->page($p)->select();
		if(!empty($pList))
		{
			foreach($pList as &$v)
			{
				$v['pic'] = get_cover($v['pic'],'path');
				$v['collect'] = intval($v['collect']);
			}
			$this->success($pList);	
		}else{
			$this->error('没有数据了');
		}
		
	}
 public function detail(){
     //根据id查询详情
     $product = D('Product');
     $id = I("id",0,'intval');
     $where["id"] = array("eq",$id);
     $info = $product->relation("store")->where($where)->field(true)->find();
     //判断是否已经收藏了 1已收藏 2 未收藏
     $iscollect=$this->_is_collected($id, 2);
     $this->assign("iscollect",$iscollect);
     if($info["pic"]!=null){
         $info["pic"]=explode(",", $info["pic"]);
     }
     $this->assign("info",$info);
 	$this->display();
 }
}